#ifndef UIEDITORWIDGET_H
#define UIEDITORWIDGET_H

#include <QWidget>
#include "mylabel.h"
#include "mybutton.h"
#include <QVector>
#include <QLineEdit>
#include <QList>
#include <QMap>
#include "eventcenter.h"
#include "mywidget.h"
#include "ResourceManger/filemanager.h"
#include "GameData/jsontranslator.h"
#include <QColorDialog>
#include "UIEditor/uilib.h"
#include "GameUI/uimanager.h"
#include "GameUI/gameuicontainer.h"
#include "GameUI/menu.h"
#include "ResourceManger/resourceswidget.h"
#include <QMainWindow>
namespace Ui {
class UIEditorWidget;
}

class UIEditorWidget : public QMainWindow
{
    Q_OBJECT

public:
    explicit UIEditorWidget(QWidget *parent = nullptr);
    ~UIEditorWidget();
    void AddLabel(LabelInfo* info = nullptr);
    void AddButton(ButtonInfo* info = nullptr);
    void AddWidget(MyWidget* widget = nullptr);
    LabelInfo* GetCurLabelInfo();
    ButtonInfo* GetCurButtonInfo();
protected:
    void closeEvent(QCloseEvent *event);
    virtual void dragEnterEvent(QDragEnterEvent *event);
    virtual void dropEvent(QDropEvent *event);
private:
    void DropBtn(QString path);
    void DropLabel(QString path);
    void DropWidget(QString path);
    void DropAlbum(QString path);
    void InitBtns();
    inline void InitLineEdit();
    void InitListWidget();
    Ui::UIEditorWidget *ui;
    ResourcesWidget* resourceWidget = nullptr;
    QMap<QString,MyWidget*> widgets;
    MyWidget* curWidget = nullptr;
    QLineEdit* l = nullptr;
    int id = 0;
    QString defaulTName = "未命名";
    QColorDialog colorDialog;
    void LoadLabel(LabelInfo* info);
    void LoadButton(ButtonInfo* info);
    void LoadWidget(int row = 0);
    //初始化修改UI信息的信号槽
    void InitEditUI();
    void SaveBtn();
    void SaveLabel();
    void SaveWidget();
    void DeleteItem();
    void DeleteWidget();
    //告知当前widget，哪个控件被选中
    void InformInfo();
    //将当前编辑的UI保存
    void Save();
    //启动软件时加载先前编辑的UI
    void Load();
    //启动软件时加载白名单UI
    void InitWhiteList();
    //启动软件时加载图鉴
    void ReadAlbum();
    //初始化GameContainer中的背景
    void InitWhiteListWidgetBackGround();
    inline void DealDefautWidgets(MyWidget* m,QWidget* w);
private slots:
    void EditFinished();
};

#endif // UIEDITORWIDGET_H
